from django.db import models
from django.contrib.auth.models import AbstractUser, UserManager as _UserManager

# Create your models here.


class UserManager(_UserManager):
    """
    define user manager for modifing 'no need email' when 'python manager.py createsuperuser '
    """
    def create_superuser(self, username, password, email=None, **extra_fields):
        super().create_superuser(
            username=username,
            password=password,
            email=email,
            extra_fields=extra_fields
        )


class Users(AbstractUser):
    """
    创建用户数据库模型
    """
    objects = UserManager()
    # A list of the field names that will be prompted for
    # when creating a user via the createsuperuser management command.
    REQUIRED_FIELDS = ['mobile']

    # help_text在api接口文档中会用到
    # verbose_name在admin站点中会用到
    mobile = models.CharField(
        max_length=11,
        unique=True,
        verbose_name='mobile num',
        help_text='mobile num',
        error_messages={
            'unique': '此手机号已注册'
        }
    )

    email_active = models.BooleanField(default=False, verbose_name='邮箱验证状态')

    class Meta:
        db_table = 'tb_users'
        verbose_name = '用户'
        verbose_name_plural = verbose_name

    def __str__(self):  # 打印对象时调用
        return self.username















